var STATS = {
		initTimeWidget : function() {
			$("#datetimepicker1").datetimepicker({//时间插件
				format: "yyyy-mm-dd hh:ii:ss",
			    language: "zh-CN",
			    autoclose: true
			}).on("changeDate", function(e){
				var date = e.date;
				var time = getTime(date);
				$("#datetimepicker2").datetimepicker("setStartDate", time);
			});
			$("#datetimepicker2").datetimepicker({//时间插件
				format: "yyyy-mm-dd hh:ii:ss",
			    language: "zh-CN",
			    autoclose: true
			}).on("changeDate", function(e){
				var date = e.date;
				var time = getTime(date);
				$("#datetimepicker1").datetimepicker("setEndDate", time);
			});
		},
		iniParameter : function () {
			var date = new Date();
			$("#datetimepicker2").val(getTime(date));//当前时间
			date.setDate(date.getDate() - 1);//设置前一天
			$("#datetimepicker1").val(getTime(date));
		},
		iniCompany : function() {
	        $("#companySelect2").select2({
	            language : "zh-CN",
	            templateResult : function (state) {
	            	if (!state.id) {
	                    return state.text;
	                }
	                var $state = $('<span><i class="fa fa-bar-chart green"></i>&nbsp;&nbsp;' + state.text + '</span>');
	                return $state;
	            },
	            templateSelection : function(selection) {
	                return $.trim(selection.text);
	            }
	        }).on ("select2:select", function (e) {
	            var data = e.params.data;
	            queryCarListByCompanyId(data.id);
	        });
	        $("#carNumberSelect2").select2({
	        	language : "zh-CN"
	        }).on ("select2:select", function (e) {
	            var data = e.params.data;
	            $("#deviceId").val(data.id);
	        });
		}
	};
	/**
	 * 返回格式化后的时间 yyyy-MM-dd HH:mm:ss
	 * @param date
	 * @returns {String}
	 */
	function getTime(date) {
		var year = date.getFullYear();
		var month = (date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1);
		var day = date.getDate()  < 10 ? "0" + date.getDate() : date.getDate();
		var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
		var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
		var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
		return year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
	}
	/**
	 * 时间格式年：月：日 时：分：秒转成时间戳函数
	 * @param date
	 * @returns {String}
	 */
	var changeTime=function changeTime(str){
	    date = str.substring(0,19);    
	    var timestamp = new Date(date).getTime();
	    return timestamp;
	};
	/**
	 * 时间戳秒转成日 时：分：秒格式函数
	 * @param timeNum (传入时间戳)
	 * @returns {String}
	 */
	function trackLineToTime(timeNum) {
	    var timeStr = new Date(timeNum);
	    var year = timeStr.getFullYear();
	    var day = timeStr.getDate()  < 10 ? "0" + timeStr.getDate() : timeStr.getDate();
	    var hour = timeStr.getHours() < 10 ? "0" + timeStr.getHours() : timeStr.getHours();
	    var minute = timeStr.getMinutes() < 10 ? "0" + timeStr.getMinutes() : timeStr.getMinutes();
	    return day+"-"+hour+":"+minute;
	}
	
	/**
	 * 秒钟转换成时间
	 * @param timeInt 
	 * @return 返回 （时 分 秒）
	 */
	function lostTimeStr(timeInt){
		 var d,h,m,s;  
		 if(timeInt<0){
		 	return '0';
		 }
	     if (timeInt>=0) {  
	         d = Math.floor(timeInt/60/60/24);  
	         h = Math.floor(timeInt/60/60%24);  
	         m = Math.floor(timeInt/60%60);  
	         s = Math.floor(timeInt%60);                     
	     } 
	     if(d<1){
	    	 if(h<1){
	        	 return m+'分'+s+'秒';
	    	 }
	    	 else{
	    		 return h+'时'+m+'分';
	    	 }
	    	
	     }
	     else {
	    	 return d+'天'+h+'时'+m+'分';
	     }
	}
	/**
	 * 时间戳转时间格式
	 * @param date 
	 * @return 返回 （年月日时分秒）
	 */
	function timestampToTime(timestamp) {
	    var date = new Date(timestamp);
	    Y = date.getFullYear() + '.';
	    M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '.';
	    D =(date.getDate() < 10 ? '0'+(date.getDate()) : date.getDate())+' ';
	    
	    h =(date.getHours() < 10 ? '0'+(date.getHours()) : date.getHours())+':'
	    
	    m =(date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes())+':';
	   
	    s =(date.getSeconds() < 10 ? '0'+(date.getSeconds()) : date.getSeconds());
	    return Y+M+D+h+m+s;
	}
	
	
